package demo.partten.filterPattern.pattern.impl;

import demo.partten.filterPattern.pattern.Person;
import demo.partten.filterPattern.pattern.Criteria;

import java.util.List;

public class AndCriteria implements Criteria {

    private List<Criteria> list;

    public AndCriteria(List<Criteria> andList) {
        list = andList;
    }

    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> result = persons;
        for (Criteria criteria: list) {
            result = criteria.meetCriteria(result);
        }
        return result;
    }
}
